﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VK.Comm;
using VK.Casemeet.Members;
using VK.Comm.Session;

namespace VK.Casemeet.Web.Front
{
    public partial class FindPassFind : System.Web.UI.Page
    {
        public string strMessage = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void butSubmit_Click(object sender, EventArgs e)
        {
            if (txtEmail.Text.Length == 0)
            {
                strMessage += "<p>帐号不能为空!</p>";
            }
            else
            {
                if (!RegexStr.CheckEmail(txtEmail.Text))
                {
                    strMessage += "<p>帐号只能为邮箱格式!</p>";
                }
            }
            if (txtCode.Text.Trim().Length == 0)
            {
                strMessage += "<p>验证码不能为空!</p>";
            }
            else
            {
                if (Util.GetCookieString("AdminValidateCode") != txtCode.Text.ToLower())
                {
                    strMessage += "<p>验证码输入错误!</p>";
                }
            }

            if (!string.IsNullOrEmpty(strMessage))
            {
                strMessage = "<dd id='vcodeMsg' class='loginMsg'>" + strMessage;
                strMessage = strMessage + "</dd>";
                return;
            }

            MemberEntity member = MemberBLL.GetMemberByEmail(txtEmail.Text);
            if (member == null)
            {
                strMessage = "<dd id='vcodeMsg' class='regMsg'><p>此帐号不存在!</p></dd>";
            }
            else
            {
                member.ValidateCode = Guid.NewGuid().ToString();
                member.ValidateDateTime = DateTime.Now;

                if (MemberBLL.UpdateMemberValidate(member.MemberID, member.ValidateCode, member.ValidateDateTime) > 0)
                {
                    SessionOperate<MemberEntity>.SetEntity("FindPassEmail", member);
                    Response.Redirect("/FindPassSend.html");
                }
            }
        }
    }
}